﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GraphDrawer {
	public partial class DiseaseSelector : UserControl {
		private ImportDisease import;
		private DatabaseModelSelector database;
		private Type diseaseMethod;
		private IWizardController wc;

		public String GraphML;
		public event RoutedEventHandler isSelectedDisease;

		private static RoutedEventHandler popUpOk;
		private static RoutedEventHandler popUpClosed;

		public DiseaseSelector(IWizardController wc) {
			InitializeComponent();

			this.wc = wc;
			import = new ImportDisease(wc);
			database = new DatabaseModelSelector(wc);
			isSelectedDisease += new RoutedEventHandler(DiseaseSelector_isSelectedDisease);
		}

		private void DiseaseSelector_isSelectedDisease(object sender, RoutedEventArgs e) {
			if (diseaseMethod == typeof(ImportDisease)) {
				GraphML = import.modelML;
			}
			else if (diseaseMethod == typeof(DatabaseModelSelector)) {
				GraphML = database.modelML;
			}
		}

		private void Database_Click(object sender, RoutedEventArgs e) {
			//App.Current.Host.Content.IsFullScreen = false;
			
			diseaseMethod = database.GetType();
			popUpOk = new RoutedEventHandler(PopUp_OK);
			popUpClosed = new RoutedEventHandler(PopUp_Closed);
			wc.PopUp.OK += popUpOk;
			wc.PopUp.Closed += popUpClosed;
			wc.PopUp.AddUserControl(database);
			database.Init();
			wc.PopUp.Visibility = Visibility.Visible;
		}

		private void Open_Click(object sender, RoutedEventArgs e) {
			//App.Current.Host.Content.IsFullScreen = false;

			diseaseMethod = import.GetType();
			popUpOk = new RoutedEventHandler(PopUp_OK);
			popUpClosed = new RoutedEventHandler(PopUp_Closed);
			wc.PopUp.OK += popUpOk;
			wc.PopUp.Closed += popUpClosed;
			wc.PopUp.AddUserControl(import);
			wc.PopUp.Visibility = Visibility.Visible;
		}

		void PopUp_OK(object sender, RoutedEventArgs e) {
			wc.PopUp.OK -= popUpOk;
			isSelectedDisease.Invoke(sender, e);
		}

		void PopUp_Closed(object sender, RoutedEventArgs e) {
			wc.PopUp.OK -= popUpOk;
		}
	}
}
